package com.xie.java_doc_searcher;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2022-08-02
 * Time:12:25
 */
// write your code here
// write your code here
import java.util.*;
public class Main {
    public static int[] monthDay = {31,28,31,30,31,30,31,31,30,31,30,31};
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int year1 = in.nextInt();
            int month1 = in.nextInt();
            int day1 = in.nextInt();
            int year2 = in.nextInt();
            int month2 = in.nextInt();
            int day2 = in.nextInt();

            earnMoney(year1,month1,day1,year2,month2,day2);
        }
    }

    public static void earnMoney(int year1,int month1,int day1,int year2,int month2,int day2){
        int money = 0;
        if(year1 + 1 == year2){
            money += yearMoney(year1) - thisYearEarnMoney(year1,month1,day1 - 1);
            money += thisYearEarnMoney(year2,month2,day2);
            System.out.println(money);
            return;
        }
        if(year1 == year2){
            money += thisYearEarnMoney(year2,month2,day2) - thisYearEarnMoney(year1,month1,day1 - 1 );
            System.out.println(money);
            return;
        }
        if(year2 > year1){
            for(int i = year1 + 1; i < year2;i++){
                money += yearMoney(i);
            }
            int count = 0;
            int year1Money = yearMoney(year1);
            int thisYear1Money = thisYearEarnMoney(year1,month1,day1 - 1);
            money = money + year1Money - thisYear1Money;
            int thisYear2Money = thisYearEarnMoney(year2,month2,day2);
            money = thisYear2Money + money;
            System.out.println(money);
            return;
        }
    }

    public static int yearMoney(int year){
        int yearMoneySum = 0;
        for(int i = 1; i <= 12; i++){
            if(isNum(i)){
                yearMoneySum += monthDay[i - 1];
            }else{
                yearMoneySum += 2 * monthDay[i - 1];
            }
        }
        yearMoneySum += leapYear(year) ? 1 : 0;
        return yearMoneySum;
    }

    public static boolean isNum(int n){
        if(n == 1){
            return false;
        }
        if (n == 2){
            return  true;
        }
        for(int i = 2; i <= Math.sqrt(n); i++){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }

    public static boolean leapYear(int year){
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }

    public static int thisYearEarnMoney(int year,int month,int day){
        int earnMoney = 0;
        if(isNum(month)){
            earnMoney = day;
        }else{
            earnMoney = 2 * day;
        }
        while(--month > 0){
            if(month == 2 && leapYear(year)){
                earnMoney =earnMoney + monthDay[month] + 1;
                continue;
            }
            if(isNum(month)){
                earnMoney +=  monthDay[month- 1];
            }else {
                earnMoney += 2 * monthDay[month - 1];
            }

        }
        return earnMoney;
    }
    public static int count(){
        int count = 0;
        for(int i = 2000; i<= 2999;i++ ){
            if (leapYear(i)){
                count++;
            }
        }
        return count;
    }
}
